Purpose |
Seed the random number generator. |
Syntax |
RANDOMIZE [number] |
Remarks |
number is a seed value that may be any numeric type. If number is not specified, the value returned by the TIMER function is used. Values returned by the random number generator (RND) depend on an initial seed value. For a given seed value, RND always returns the same sequence of values, yielding a predictable pseudo-random number sequence. Thus, any program that depends on RND will run exactly the same way each time unless a different seed is given. The default seed can be duplicated with the following statement: RANDOMIZE CVS(CHR$(255,255,255,255)) Note that each thread has its own, independent random number seed. |
See also |
|
Example |
' Seed generator and get 5 random values RANDOMIZE 1.5! FOR I& = 1 TO 5 Table(I&) = RND(1,100) NEXT I&
' Reseeding with the same starting value ' means you get the same sequence of values! RANDOMIZE 1.5! FOR I& = 1 TO 5 Table(I&) = RND(1,100) NEXT I&
' Now reseed from the TIMER and we get ' a completely different set of values: RANDOMIZE TIMER FOR I& = 1 TO 5 Table(I&) = RND(1,100) NEXT I& |